package com.sl.biz.modular.ai.service.impl;

import cn.hutool.core.util.StrUtil;
import com.sl.biz.modular.ai.dao.domain.entity.AiConfigDO;
import com.sl.biz.modular.ai.dao.service.AiChatConfigDaoService;
import com.sl.biz.modular.ai.dao.service.AiChatHistoryDaoService;
import com.sl.biz.modular.ai.dao.service.AiConfigDaoService;
import com.sl.biz.modular.ai.service.AiConfigBizService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class AiConfigBizServiceImpl implements AiConfigBizService {

    private final AiConfigDaoService aiConfigDaoService;

    private final AiChatConfigDaoService aiChatConfigDaoService;

    private final AiChatHistoryDaoService aiChatHistoryDaoService;

    @Override
    public List<AiConfigDO> list(AiConfigDO jobConfigDO) {
        return aiConfigDaoService.queryByCondition(jobConfigDO);
    }

    @Override
    public AiConfigDO getById(AiConfigDO cdcConfigDO) {
        return aiConfigDaoService.getById(cdcConfigDO);
    }

    @Override
    public Boolean save(AiConfigDO cdcConfigDO) {
        String id = cdcConfigDO.getId();
        if (StrUtil.isBlank(id)) {
            cdcConfigDO.setDisableFlag(1);
        }

        return aiConfigDaoService.saveOrUpdate(cdcConfigDO);
    }

    @Override
    public Boolean setStatusFlag(AiConfigDO assertUserUse) {
        return aiConfigDaoService.updateDisableFlag(assertUserUse);
    }

    @Override
    public Boolean removeById(AiConfigDO cdcConfigDO) {

        aiChatConfigDaoService.removeByAiId(cdcConfigDO.getId());

        aiChatHistoryDaoService.removeByAiId(cdcConfigDO.getId());

        Boolean result = aiConfigDaoService.removeById(cdcConfigDO.getId());
        return result;
    }

    @Override
    public AiConfigDO getByCode(String aiCode) {
       return aiConfigDaoService.getByCode(aiCode);
    }
}
